package com.inei.eea2014.model.dao;

import java.util.ArrayList;
import java.util.List;
import com.inei.eea2014.model.connection.UtilDB;
import com.inei.eea2014.model.entity.Dis;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DisDao implements ICRUD<Dis>{

	// variables
		private UtilDB util;
		private SQLiteDatabase db;
		private Cursor cursor = null;

		// constructor
		public DisDao(Context context) {
			util = new UtilDB(context);
		}

		// metodos ICRUD
		@Override
		public Dis buscar(Dis o) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public List<Dis> leer() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int crear(Dis o) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public int actualizar(Dis o) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public int eliminar(Dis o) {
			// TODO Auto-generated method stub
			return 0;
		}

		// otros metodos
		public List<Dis> leer(String ccdd, String ccpp) {
			List<Dis> lista = null;
			db = util.getReadableDatabase();
			cursor = db.rawQuery("select * from Dis where ccdd=? and ccpp=?",
					new String[] { ccdd + "", ccpp + "" });
			if (cursor.moveToFirst()) {
				lista = new ArrayList<Dis>();
				while (!cursor.isAfterLast()) {
					Dis obj = new Dis();
					obj.setCcdi(cursor.getString(cursor.getColumnIndex("ccdi")));
					obj.setNom_dist(cursor.getString(cursor
							.getColumnIndex("nom_dist")));
					lista.add(obj);
					cursor.moveToNext();
				}
			}
			Cerrar();
			return lista;
		}

		private void Cerrar() {
			if (cursor != null) {
				cursor.close();
			}
			if (db.inTransaction()) {
				db.endTransaction();
			}
			if (db.isOpen()) {
				db.close();
			}
		}
}
